﻿package com.wandian.util
{

    public class FormatMoney extends Object
    {
        public static var _formatMoney:FormatMoney;

        public function FormatMoney() : void
        {
            return;
        }

        public static function setFormatMoney(moneyNum:Number) : String
        {
            var i:uint;
            var insertStr:* = function (param1:String, param2:String = ",", param3:uint = 0) : String
            {
                var fmtMoney:String = "";
                param3 = param3 <= param1.length ? (param3) : (param1.length);
                fmtMoney = fmtMoney + param1.substring(0, param3);
                fmtMoney = fmtMoney + param2;
                fmtMoney = fmtMoney + param1.substring(param3, param1.length);
                return fmtMoney;
            }
            ;
            var moneyStr:String = String(moneyNum);
            var tmpStr:String = moneyStr.substr(0, moneyStr.indexOf(".") != -1 ? (moneyStr.indexOf(".")) : (moneyStr.length));
            var commaNum:int = tmpStr.length % 3 != 0 ? (tmpStr.length / 3 >> 0) : ((tmpStr.length / 3 >> 0) - 1);
            while (i < commaNum)
            {
                
                tmpStr = insertStr(tmpStr, ",", tmpStr.length - (i + 1) * 3 - i);
                i = (i + 1);
            }
            tmpStr = tmpStr + (moneyStr.indexOf(".") != -1 ? (moneyStr.substring(moneyStr.indexOf("."), moneyStr.length)) : (""));
            return tmpStr;
        }

    }
}
